Routines (alphabetical) > Routines: C > COMPILE_OPT

COMPILE_OPT

Syntax | Arguments | Version History

The COMPILE_OPT statement allows you to give the IDL compiler information that changes some of the default rules for compiling the function or procedure within which the COMPILE_OPT statement appears.

We recommend the use of

COMPILE_OPT IDL2

in all new code intended for use in a reusable library. We further recommend the use of

COMPILE_OPT idl2, HIDDEN

in all such routines that are not intended to be called directly by regular users (e.g. helper routines that are part of a larger package).

Syntax

COMPILE_OPT opt1 [, opt2, ..., optn]

Arguments

optn

This argument can be any of the following:

   COMPILE_OPT DEFINT32, STRICTARR

Examples of the Effect of the DEFINT32 Argument

Constant

Normal Type

DEFINT32 Type

Without type specifier:

 

 

42

INT

LONG

'2a'x

INT

LONG

42u

UINT

ULONG

'2a'xu

UINT

ULONG

With type specifier:

 

 

0b

BYTE

BYTE

0s

INT

INT

0l

LONG

LONG

42.0

FLOAT

FLOAT

42d

DOUBLE

DOUBLE

42us

UINT

UINT

42ul

ULONG

ULONG

42ll

LONG64

LONG64

42ull

ULONG64

ULONG64

A side-effect of making a routine hidden is that IDL will not print a “Compile module” message for it when it is compiled from the library to satisfy a call to it. This makes hidden routines appear built-in to the user.

Background

A predicate expression is an expression that is evaluated as being “true” or “false” as part of a statement that controls program execution. IDL evaluates such expressions in the following contexts:

By default, IDL uses the following rules to determine whether an expression is true or false:

The LOGICAL_PREDICATE option alters the way IDL evaluates predicate expressions. When LOGICAL_PREDICATE is set for a routine, IDL uses the following rules to determine whether an expression is true or false:

Note on the NOT Operator

When using the LOGICAL_PREDICATE compile option, you must be aware of the fact that applying the IDL NOT operator to integer data computes a bitwise negation (1’s complement), and is generally not applicable for use in logical computations. Consider the common construction:

WHILE (NOT EOF(lun)) DO BEGIN

...

ENDWHILE

The EOF function returns 0 while the file specified by LUN has data left, and returns 1 when hits the end of file. However, the expression “NOT 1” has the numeric value ‑2. When the LOGICAL_PREDICATE option is not in use, the WHILE statement sees -2 as false; if the LOGICAL_PREDICATE is in use, ‑2 is a true value and the above loop will not terminate as desired.

The proper way to write the above loop uses the ~ logical negation operator:

WHILE (~ EOF(lun)) DO BEGIN

...

ENDWHILE

Note that this version will work properly whether or not the LOGICAL_PREDICATE compile option is in use. Logical negation operations should always use the ~ operator in preference to the NOT operator, reserving NOT exclusively for bitwise computations.

Use of STRICTARR can eliminate many uses of the FORWARD_FUNCTION definition.

Note: STRICTARR has no effect on the use of parentheses to reference structure tags using the tag index, which is not an array indexing operation. For example, no syntax error will occur when compiling the following code:

COMPILE_OPT STRICTARR

mystruct = {a:0, b:1}

byindex_0 = mystruct.(0)

Version History

5.3

Introduced

5.6

Added STRICTARRSUBS option

6.0

Added LOGICAL_PREDICATE option